<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xml:lang="en" lang="en">
    
	<ui:composition template="/WEB-INF/templates/layout.xhtml">

		<ui:define name="conteudo">
			
			<h:form>
				
				<rich:panel>
					<h:outputText value="Fabricante : "/>
					<h:inputText value="#{telaFabricante.nome}" id="nomeFabricante" style="width: 400px;"/>
					<a4j:commandButton value="Pesquisar" action="#{telaFabricante.pesquisar}" reRender="tabelaFabricantes"/>
				</rich:panel>
				
				<a4j:region>
					
					<rich:dataTable value="#{telaFabricante.listaObjetos}"
												  var="fabricante"
												  rows="15"
												  id="tabelaFabricantes"
												  width="100%">
												  
						<f:facet name="header">
							<h:panelGrid columns="2">
								<h:outputText value="Fabricantes "/>
								<a4j:commandLink ajaxSingle="true" id="newLink" oncomplete="#{rich:component('editPanel')}.show()" action="#{telaFabricante.novoFabricante}">
									<h:graphicImage value="/imagens/new.png" style="border: 0;"/>
								</a4j:commandLink> 
								<rich:toolTip for="newLink" value="Novo Fabricante" />
							</h:panelGrid>
						</f:facet>
						
						<!--  COLUNA : ACOES -->
						<rich:column width="30px;">
							<f:facet name="header">
								<h:outputText value="Ações"/>
							</f:facet>
							
							<a4j:commandLink ajaxSingle="true" id="editLink" oncomplete="#{rich:component('editPanel')}.show()">
								<h:graphicImage value="/imagens/edit.gif" style="border: 0;"/>
								<f:setPropertyActionListener  target="#{telaFabricante.objetoSelecionado}"  value="#{fabricante}"/>
							</a4j:commandLink> 
							<rich:toolTip for="editLink" value="Alterar" />
			                
			                <a4j:commandLink ajaxSingle="true" id="deletelink" oncomplete="#{rich:component('deletePanel')}.show()">
			                	<h:graphicImage value="/imagens/delete.gif" style="border:0" />
			                    <f:setPropertyActionListener value="#{fabricante}" target="#{telaFabricante.objetoSelecionado}" />
			                </a4j:commandLink>
			                <rich:toolTip for="deletelink" value="Apagar" />
						</rich:column>
						
						<!--  COLUNA : NOME -->
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Nome"/>
							</f:facet>
							<h:outputText value="#{fabricante.nome}" id="nome"/>
						</rich:column>
						
						<f:facet name="footer">
                    		<rich:datascroller renderIfSinglePage="false" maxPages="5" />
                		</f:facet>
					
					</rich:dataTable>
					
				</a4j:region>
				
			</h:form>
			
			<!-- PAINEL MODAL  DE EDIÇÃO -->
			<rich:modalPanel id="editPanel" autosized="true" width="500">
				
				<f:facet name="header">
					<h:outputText value="Modificar Fabricante"/>
				</f:facet>
				<f:facet name="controls">
	            	<h:panelGroup>
		                <h:graphicImage value="../imagens/close.png" id="hidelink" styleClass="hidelink" />
		                <rich:componentControl for="editPanel" attachTo="hidelink" operation="hide" event="onclick" />
	            	</h:panelGroup>
	        	</f:facet>
				
				<!-- FORMULARIO DO PAINEL MODAL -->
				<h:form>
		            <rich:messages style="color:red;" />
		            <h:panelGrid columns="1">
		                <a4j:outputPanel ajaxRendered="true">
		                    <h:panelGrid columns="2">
		                        <h:outputText value="Fabricante" />
		                        <h:inputText value="#{telaFabricante.objetoSelecionado.nome}" maxlength="100" style="width: 400px"/>
		                    </h:panelGrid>
		                    <!--  <rich:message showSummary="true" showDetail="false" for="price" />-->
		                    <h:messages style="color:red"/>
		                </a4j:outputPanel>
		                <a4j:commandButton value="Salvar"
		                    									 action="#{telaFabricante.salvar}"
		                    									 reRender="tabelaFabricantes"
		                   										 oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editPanel')}.hide();" />
		            </h:panelGrid>
		        </h:form>
        
			</rich:modalPanel>
			
			<!-- PAINEL MODAL DE EXCLUSÃO -->
			<rich:modalPanel id="deletePanel" autosized="true" width="200">
		        <f:facet name="header">
		            <h:outputText value="Remove este fabricante?" style="padding-right:15px;" />
		        </f:facet>
		        <f:facet name="controls">
		            <h:panelGroup>
		                <h:graphicImage value="/imagens/close.png" styleClass="hidelink" id="hidelink2" />
		                <rich:componentControl for="deletePanel" attachTo="hidelink2" operation="hide" event="onclick" />
		            </h:panelGroup>
		        </f:facet>
		        <h:form>
		            <table width="100%">
		                <tbody>
		                    <tr>
		                        <td align="center" width="50%">
		                        	<a4j:commandButton value="Sim" 
		                        	                                         ajaxSingle="true" 
		                        	                                         action="#{telaFabricante.excluir}"
		                            										 oncomplete="#{rich:component('deletePanel')}.hide();"
		                            										 reRender="tabelaFabricantes" />
		                        </td>
		                        <td align="center" width="50%">
		                        	<a4j:commandButton value="Cancelar" onclick="#{rich:component('deletePanel')}.hide();return false;"/>
		                        </td>
		                    </tr>
		                </tbody>
		            </table>
		        </h:form>
		    </rich:modalPanel>
			
			 <a4j:status onstart="#{rich:component('wait')}.show()"  onstop="#{rich:component('wait')}.hide()" />
		    <rich:modalPanel id="wait" autosized="true" width="200" height="120" moveable="false" resizeable="false">
		        <f:facet name="header">
		            <h:outputText value="Processando" />
		        </f:facet>
		        <h:outputText value="Aguarde por favor..." />
		    </rich:modalPanel>
			
		</ui:define>
	</ui:composition>
	
	
</html>
